package mythread;

public class MyRunnable implements Runnable{
    public volatile boolean isQuit = false;

    @Override
    public void run() {
        while (!isQuit) {
            System.out.println(Thread.currentThread().getName()+"我在忙着转账!");
            try {
                Thread.sleep(1000);

            }catch (InterruptedException e){
                e.printStackTrace();
            }
        }
        System.out.println(Thread.currentThread().getName()+"转错账了!");
    }

    public static void main(String[] args) throws InterruptedException {
        MyRunnable target= new MyRunnable();
        Thread thread = new Thread(target,"张三");
        System.out.println(Thread.currentThread().getName()+"：开始转账!");
        thread.start();
        Thread.sleep(10*1000);
        System.out.println(Thread.currentThread().getName()+":老板说对面是个骗子，我得停止转钱了@！！");
        target.isQuit = true;
    }

    public void run1() {
        System.out.println("实现 Runnable 类创建的线程");
    }

    public static void main2(String[] args) {
        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                System.out.println("使用匿名内部类创建 Runnable 子类对象");
            }
        };
        runnable.run();
    }
    public static void main1(String[] args) {
        MyRunnable t = new MyRunnable();
        t.run();
    }
}
